package com.lagou.homework.statistics

case class UserInfo(userName: String, location: String, startTime: Int, duration: Int)

object Location {
  def main(args: Array[String]): Unit = {
    val userInfoList: List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserB", "LocationB", 10, 60),
      UserInfo("UserB", "LocationB", 11, 80)
    )

    val userMap = userInfoList.groupBy(t => t.userName + "," + t.location)
    println(s"$userMap\n")

    var firstTime = 0

    val totalMap = userMap.mapValues(t => {
      firstTime = t.head.startTime
      t.map(x => x.duration).sum
    })

    totalMap.foreach {
      case (data, totalTime) => println(s"$data,$firstTime,$totalTime")
    }
  }
}